//
//  Loading.m
//  Maze1
//
//  Created by Lin Tian on 9/26/11.
//  Copyright 2011 tina. All rights reserved.
//

#import "Loading.h"

#define PROGRESS1 1

@implementation Loading
@synthesize room = _room;
@synthesize player = _localPlayer;

+(CCScene*) scene
{
	CCScene *myScene = [CCScene node];
	
	Loading *loadingPage = [Loading node];
	
	[myScene addChild:loadingPage z:2 tag:LoadingPage];
	
	return myScene;
}

-(id)init
{
	if ((self = [super init])) {
        CCProgressTimer *timer = [CCProgressTimer progressWithFile:@"progress_bar.png"];
        timer.type = kCCProgressTimerTypeHorizontalBarLR;
        timer.percentage = 0;
        timer.position = CGPointMake(100, 100);
        [self addChild:timer z:1 tag:PROGRESS1];
        
        [self schedule:@selector(updateTime:)];
	}
	return self;
}

-(void)dealloc
{
	[super dealloc];
}

-(void) updateTime:(ccTime)dt
{
    CCNode *node =[self getChildByTag:PROGRESS1];
    NSAssert([node isKindOfClass:[CCProgressTimer class]],@"node is not a progressTimer node");
    
    CCProgressTimer *timer = (CCProgressTimer*)node;
    timer.percentage = self.player.loadingProgress;
    if (timer.percentage >=100) {
        timer.percentage = 100;
        [PackageParser sharedPackageParser].state = PlayerStateLoadingGameComplete;
    }
}
@end
